package com.summer.common.lib.core.validator.customize;

import com.summer.common.lib.core.validator.annotations.IdValid;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class IdValidator implements ConstraintValidator<IdValid, Long> {

    private int idRange = 0;

    @Override
    public void initialize(IdValid constraintAnnotation) {
        this.idRange = constraintAnnotation.idRange();
    }

    @Override
    public boolean isValid(Long value, ConstraintValidatorContext context) {
        return value.intValue() > idRange;
    }
}
